﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class HisEducationBLL : IHisEducationBLL
    {
        private static readonly IHisEducationDAL dal = DataAccess.CreateHisEducations();

        private HisEducationInfo hisInfo = new HisEducationInfo();
        private EmployeeInfo empInfo = new EmployeeInfo();
        private MasEducationDegreeInfo degreeInfo = new MasEducationDegreeInfo();
        private MasEducationQualificationInfo qualInfo = new MasEducationQualificationInfo();
        private MasEducationMajorInfo majorInfo = new MasEducationMajorInfo();
        private MasEducationInstituteInfo insInfo = new MasEducationInstituteInfo();

        public IList<HisEducationInfo> ListHisEducationsBySequence(string Sequence)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return dal.ListHisEducations(new HisEducationInfo(Seq));
        }
        public IList<HisEducationInfo> ListHisEducations(string Employee)
        {
            if (Employee.Length > 0)
                empInfo.Sequence = Int32.Parse(Employee);

            hisInfo.Employee = empInfo;
            return dal.ListHisEducations(hisInfo);
        }
        public DataSet LoadEducationHistories(Nullable<int> Sequence, string Employee)
        {
            if (Employee.Length > 0)
            {
                empInfo.Sequence = Int32.Parse(Employee);
                hisInfo.Employee = empInfo;
            }
            if (Sequence.HasValue)
                hisInfo.Sequence = (int)Sequence;
            
            return dal.LoadEducationHistories(hisInfo);
        }
        public void Insert(string Employee, string Degree, string Qualification, string Major
            , string Institute, Nullable<int> EduStartYear, Nullable<int> EduEndYear
            , Nullable<DateTime> StartDate, Nullable<DateTime> EndDate, Nullable<decimal> GPA
            , string Remarks, int CreatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            degreeInfo.Sequence = Degree.Length > 0 ? Int32.Parse(Degree) : 0;
            qualInfo.Sequence = Qualification.Length > 0 ? Int32.Parse(Qualification) : 0;
            majorInfo.Sequence = Major.Length > 0 ? Int32.Parse(Major) : 0;
            insInfo.Sequence = Institute.Length > 0 ? Int32.Parse(Institute) : 0;

            try
            {
                dal.Insert(new HisEducationInfo(0, empInfo, degreeInfo, qualInfo, majorInfo
                , insInfo, EduStartYear, EduEndYear, StartDate, EndDate, GPA, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Employee, string Degree, string Qualification, string Major
            , string Institute, Nullable<int> EduStartYear, Nullable<int> EduEndYear
            , Nullable<DateTime> StartDate, Nullable<DateTime> EndDate, Nullable<decimal> GPA
            , string Remarks, int UpdatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            degreeInfo.Sequence = Degree.Length > 0 ? Int32.Parse(Degree) : 0;
            qualInfo.Sequence = Qualification.Length > 0 ? Int32.Parse(Qualification) : 0;
            majorInfo.Sequence = Major.Length > 0 ? Int32.Parse(Major) : 0;
            insInfo.Sequence = Institute.Length > 0 ? Int32.Parse(Institute) : 0;

            try
            {
                dal.Update(new HisEducationInfo(Sequence, empInfo, degreeInfo, qualInfo, majorInfo
                , insInfo, EduStartYear, EduEndYear, StartDate, EndDate, GPA, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
